package com.zhangj.springcloud.controller;

import com.zhangj.springcloud.entites.CommonResult;
import com.zhangj.springcloud.entites.Payment;
import com.zhangj.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName PaymentController
 * @Description
 * @Author zhangjie
 * @Date 2022/1/15 14:01
 * @Version 1.0
 */

@RestController
@Slf4j
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private Integer port;

    @RequestMapping("/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id")Long id){

        try { TimeUnit.SECONDS.sleep(3); }catch (Exception e) {e.printStackTrace();}

        Payment payment = paymentService.getPaymentById(id);

        System.out.println("port = " + port);

        System.out.println("payment = " + payment);
        System.out.println("payment = " + payment);
        System.out.println("payment = " + payment);
        log.info("查询订单,Id为====>" + id);
        return new CommonResult<>(200,"查询成功",payment);
    }

    @RequestMapping("/payment/creat")
    public CommonResult<Payment> creatPayment(@RequestBody Payment payment){

        try {
            paymentService.creat(payment);
            log.info("添加了订单====>" + payment );
            return new CommonResult<>(200,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            log.info("添加订单失败=====>" + payment );
            return new CommonResult<>(500,"添加失败",payment);
        }
    }
}
